﻿/// <reference path="../../js/utils.js" />
'use strict';

define([
    'backbone',
    'screenView',

    'common/models/driver.model',
    'common/models/truck.model',

    'backgrid.all',
],
function (Backbone, ScreenView, TruckModel, Backgrid) {
    var View = ScreenView.extend({
        super: null,

        name: 'events',
        title: 'Vencimientos',

        initialize: function () {
            this.super = View.__super__;

            return this.super.initialize.apply(this, arguments);
        },

        render: function () {
            this.super.render.apply(this);

            /* First render actions. */
            if (!this.rendered) {

                var DriverEventModel = Backbone.Model.extend({
                    defaults: {
                        description: 'Registro',
                        nextDatetime: '2015-06-07',
                        notify: true,
                        owner: 'Nicolas Lareu',
                        previousDatetime: '2015-02-24',
                        reminderDatetime: '2015-05-07',
                        repeatFreq: 'Anual',
                        status: 0,
                    },
                });

                var DriverEventCollection = Backbone.Collection.extend({
                    defaults: {
                        model: DriverEventModel,
                    }
                });

                var driverEventCol = new DriverEventCollection();


                this.driverEventsGrid = App.utils.grids.events.driver(driverEventCol);
                this.driverEventsGrid.render();
                // Render the grid and attach the Grid's root to your HTML document
                this.$el.find('#eventsDriverGrid').append(this.driverEventsGrid.el);


                driverEventCol.set([
                    new DriverEventModel({ status: 1, repeatFreq: 'Mensual', }),
                    new DriverEventModel({ repeatFreq: 'Cada 3 meses', }),
                    new DriverEventModel({ status: 2, }),
                ]);




                var TruckEventModel = Backbone.Model.extend({
                    defaults: {
                        description: 'Seguro',
                        nextDatetime: '2015-06-07',
                        notify: true,
                        owner: 'Nicolas Lareu',
                        previousDatetime: '2015-02-24',
                        reminderDatetime: '2015-05-07',
                        repeatFreq: 'Anual',
                        status: 0,
                    },
                });

                var TruckEventsCollection = Backbone.Collection.extend({
                    defaults: {
                        model: TruckEventModel,
                    }
                });

                var truckEventCol = new TruckEventsCollection();


                this.truckEventsGrid = App.utils.grids.events.truck(truckEventCol);
                this.truckEventsGrid.render();
                // Render the grid and attach the Grid's root to your HTML document
                this.$el.find('#eventsTruckGrid').append(this.truckEventsGrid.el);


                this.semiEventsGrid = App.utils.grids.events.truck(truckEventCol);
                this.semiEventsGrid.render();
                // Render the grid and attach the Grid's root to your HTML document
                this.$el.find('#eventsSemiGrid').append(this.semiEventsGrid.el);


                truckEventCol.set([
                    new TruckEventModel({ description: 'SENASA', status: 1, }),
                    new TruckEventModel({ repeatFreq: 'Mensual', }),
                    new TruckEventModel({ status: 2, }),
                    new TruckEventModel({ description: 'SENASA', repeatFreq: 'Cada 3 meses', }),
                    new TruckEventModel(),
                ]);


                /* Indicates that the view was rendered at least one time. */
                this.rendered = true;
            }
                /* Not first render actions. */
            else {

            }


            return this;
        },
    });

    return View;
});